(use-package go-mode
  :ensure t
  :mode "\\.go\\'"
  ;; :custom (gofmt-command "goimports")
  :custom (tab-width 4)
  )

(use-package lsp-mode
  :ensure t
  :commands (lsp lsp-deferred)
  :hook (go-mode . lsp-deferred))

;; Set up before-save hooks to format buffer and add/delete imports.
;; Make sure you don't have other gofmt/goimports hooks enabled.
(defun lsp-go-install-save-hooks ()
  (add-hook 'before-save-hook #'lsp-format-buffer t t)
  (add-hook 'before-save-hook #'lsp-organize-imports t t))

(add-hook 'go-mode-hook #'lsp-go-install-save-hooks)

;; Optional - provides fancier overlays.
(use-package lsp-ui
  :ensure t
  :commands lsp-ui-mode
  :bind (("C-;" . lsp-ui-peek-find-references))
  )

;; Optional - provides snippet support.
;(use-package yasnippet
;  :ensure t
;  :commands yas-minor-mode
;  :hook (go-mode . yas-minor-mode))

;;(setq lsp-gopls-use-placeholders nil)

(provide 'go)
;;; go.el ends here
